//
//  ZJQuestionAnTableViewCell.m
//  ShangHaiHuDongApp
//
//  Created by ZJ on 2017/6/22.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "ZJQuestionAnTableViewCell.h"

@interface ZJQuestionAnTableViewCell ()
/** 问题 */
@property (nonatomic, strong) UILabel *label;
/** 回答个数 */
@property (nonatomic, strong) UILabel *answerNumber;
/** 问题内容 */
@property (nonatomic, strong) UILabel *contentLabel;
/** 图标 */
@property (nonatomic, strong) UIImageView *icon;
/** 标记 */
@property (nonatomic, strong) UILabel *markLabel;
/** time */
@property (nonatomic, strong) UILabel *timeLabel;
/** 分割线 */
@property (nonatomic, strong) UILabel *spaceLabel;

@end

@implementation ZJQuestionAnTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.contentView addSubview:self.spaceLabel];
        [self.contentView addSubview:self.label];
        [self.contentView addSubview:self.answerNumber];
        [self.contentView addSubview:self.contentLabel];
        [self.contentView addSubview:self.icon];
        [self.contentView addSubview:self.markLabel];
        [self.contentView addSubview:self.timeLabel];
        
        self.spaceLabel.sd_layout
        .topSpaceToView(self.contentView, 0)
        .leftSpaceToView(self.contentView, 0)
        .rightSpaceToView(self.contentView, 0)
        .heightIs(8 * [UIScreen zj_screenHScale]);
        
        self.label.sd_layout
        .topSpaceToView(self.spaceLabel, 12 * [UIScreen zj_screenHScale])
        .leftSpaceToView(self.contentView, 12 * [UIScreen zj_screenWScale])
        .widthIs(80 * [UIScreen zj_screenWScale])
        .heightIs([NSString heightWithTextFont:self.label.font]);
        
        self.answerNumber.sd_layout
        .topEqualToView(self.label)
        .leftSpaceToView(self.label, 0)
        .rightSpaceToView(self.contentView, 12 * [UIScreen zj_screenWScale])
        .heightRatioToView(self.label, 1);
        
        self.contentLabel.sd_layout
        .topSpaceToView(self.label, 8 * [UIScreen zj_screenHScale])
        .leftEqualToView(self.label)
        .widthIs([UIScreen zj_screenWith] - 24 * [UIScreen zj_screenWScale])
        .heightIs(10);
        
        self.icon.sd_layout
        .topSpaceToView(self.contentLabel, 10 * [UIScreen zj_screenHScale])
        .leftEqualToView(self.contentLabel)
        .widthIs([NSString heightWithTextFont:self.markLabel.font])
        .heightEqualToWidth();
        
        self.timeLabel.sd_layout
        .topEqualToView(self.icon)
        .rightEqualToView(self.answerNumber)
        .heightRatioToView(self.icon, 1)
        .widthIs(100 * [UIScreen zj_screenWScale]);
        
        self.markLabel.sd_layout
        .topEqualToView(self.icon)
        .rightSpaceToView(self.timeLabel, 10 * [UIScreen zj_screenWScale])
        .leftSpaceToView(self.icon, 5 * [UIScreen zj_screenWScale])
        .heightRatioToView(self.icon, 1);
        
    }
    return self;
}


#pragma mark - Setter
- (void)setModel:(ZJQuestionAnModel *)model{
    _model = model;
    
    self.contentLabel.text = model.QUESTION;
    self.contentLabel.sd_layout
    .topSpaceToView(self.label, 8 * [UIScreen zj_screenHScale])
    .leftEqualToView(self.label)
    .widthIs([UIScreen zj_screenWith] - 24 * [UIScreen zj_screenWScale])
    .heightIs([self.contentLabel getLableSizeWithMaxWidth:self.contentLabel.width].height);
    [self.contentLabel updateLayout];
    if (self.headLine.length == 0) {
       self.answerNumber.text = [NSString stringWithFormat:@"%@ 回答",model.CU];
    }
    self.markLabel.text = [model.TYPE stringByReplacingOccurrencesOfString:@"," withString:@"  "];//替换字符
    self.timeLabel.text = [NSDateFormatter stringWithDate: [NSDateFormatter dateTimeWithString:model.TIME]];
}

#pragma mark - Getters
- (UILabel *)label{
    if (_label == nil){
        _label = [UILabel new];
        _label.textColor = [UIColor themeColor];
        _label.text = @"问题 :";
        _label.font = [UIFont titleTextFont];
    }
    return _label;
}
- (UILabel *)answerNumber{
    if (_answerNumber == nil){
        _answerNumber = [UILabel new];
        _answerNumber.textColor = [UIColor zj_colorWithHexString:@"ed4240"];
        _answerNumber.font = [UIFont systemFontOfSize:13 * [UIScreen zj_textFontScale]];
        _answerNumber.textAlignment = NSTextAlignmentRight;
   }
    return _answerNumber;
}
- (UILabel *)contentLabel{
    if (_contentLabel == nil){
        _contentLabel = [UILabel new];
        _contentLabel.textColor = [UIColor textBlackColor];
        _contentLabel.font = [UIFont titleTextFont];
        _contentLabel.characterSpace = 1;
        _contentLabel.lineSpace = 4 * [UIScreen zj_screenHScale];
        _contentLabel.numberOfLines = 0;
    }
    return _contentLabel;
}

- (UIImageView *)icon{
    if (_icon == nil){
        _icon = [UIImageView new];
        _icon.contentMode = UIViewContentModeCenter;
        _icon.image = [UIImage imageNamed:@"qa_lable"];
    }
    return _icon;
}

- (UILabel *)markLabel{
    if (_markLabel == nil){
        _markLabel = [UILabel new];
        _markLabel.textColor = [UIColor zj_colorWithHexString:@"a8a8a8"];
        _markLabel.font = self.answerNumber.font;
    }
    return _markLabel;
}
- (UILabel *)timeLabel{
    if (_timeLabel == nil){
        _timeLabel = [UILabel new];
        _timeLabel.textColor = [UIColor zj_colorWithHexString:@"a8a8a8"];
        _timeLabel.font = self.answerNumber.font;
        _timeLabel.textAlignment = NSTextAlignmentRight;
    }
    return _timeLabel;
}

- (UILabel *)spaceLabel{
    if (_spaceLabel == nil){
        _spaceLabel = [UILabel new];
        _spaceLabel.backgroundColor = [UIColor zj_colorWithHexString:@"f2f2f2"];
    }
    return _spaceLabel;
}
@end
